From f1bcf0d91e7e7b9854bdc9df0b326b484dc38e25 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:33:14 -0700 Subject: [PATCH] jeeps function pointers, GPS_PPacket const correctness, GPS_Serial_[OSP]Packet -> GPS_Serial_Packet (#1215) * use using for jeeps function prototypes. * const correctness wrt GPS_PPacket. The important bit here is in gpssend.cc, Build_Serial_Packet used to rececive a 1KB packet by copy, now it is by const reference. * delete accidentally committed file. * rename GPS_PPacket -> GPS_Packet. original jeeps used GPS_SXXX, GPS_OSXXX, GPS_PXXX for the structure tag, a typedef of the structure, and a pointer to a typedef of the structure. In the case of GPS_PPacket this convention was no longer followed. * change GPS_Packet back to a structure. * try harder to change GPS_Packet back to a struct. * clean up GPS_Serial_[SOP]Packet. * catch some missed renames up. clion on linux missed some windows only renames. --- jeeps/gps.h | 23 +----- jeeps/gpsapp.cc | 170 ++++++++++++++++++++--------------------- jeeps/gpsapp.h | 10 +-- jeeps/gpscom.cc | 4 +- jeeps/gpsdevice.cc | 10 +-- jeeps/gpsdevice.h | 21 ++--- jeeps/gpsdevice_usb.cc | 2 +- jeeps/gpsread.cc | 10 +-- jeeps/gpsread.h | 4 +- jeeps/gpsrqst.cc | 8 +- jeeps/gpssend.cc | 20 ++--- jeeps/gpssend.h | 6 +- jeeps/gpsserial.cc | 8 +- jeeps/gpsusbcommon.h | 6 +- jeeps/gpsusbint.h | 6 +- jeeps/gpsusbread.cc | 2 +- jeeps/gpsusbsend.cc | 2 +- 17 files changed, 149 insertions(+), 163 deletions(-) diff --git a/jeeps/gps.h b/jeeps/gps.h index 951d8263a..f9e9f5484 100644 --- a/jeeps/gps.h +++ b/jeeps/gps.h @@ -28,21 +28,14 @@ extern int32 gps_show_bytes; extern char gps_categories[16][17]; -typedef struct GPS_SPacket { - US type; - uint32 n; - UC* data; -} GPS_OPacket; - -class GPS_PPacket { -public: +struct GPS_Packet { US type{0}; uint32 n{0}; UC data[MAX_GPS_PACKET_SIZE]{}; }; -typedef struct GPS_Serial_SPacket { +struct GPS_Serial_Packet { UC dle; UC type; UC n; @@ -50,15 +43,7 @@ typedef struct GPS_Serial_SPacket { UC chk; UC edle; UC etx; -} GPS_Serial_OPacket, *GPS_Serial_PPacket; - -typedef struct GPS_SProduct_Data_Type { - int16 id; - int16 version; - char desc[MAX_GPS_PACKET_SIZE]; -} GPS_OProduct_Data_Type, *GPS_PProduct_Data_Type; - - +}; typedef struct GPS_SPvt_Data_Type { @@ -247,7 +232,7 @@ typedef struct GPS_SCourse_Limits { } GPS_OCourse_Limits, *GPS_PCourse_Limits; -typedef int (*pcb_fn)(int, GPS_SWay**); +using pcb_fn = int (*)(int, GPS_SWay**); #include "jeeps/gpsdevice.h" #include "jeeps/gpssend.h" diff --git a/jeeps/gpsapp.cc b/jeeps/gpsapp.cc index 95e487629..c66ad672c 100644 --- a/jeeps/gpsapp.cc +++ b/jeeps/gpsapp.cc @@ -47,7 +47,7 @@ double gps_save_lon; #define XMIN(a,b) (a < b? a : b) static int32 GPS_A000(const char* port); -static void GPS_A001(GPS_PPacket& packet); +static void GPS_A001(const GPS_Packet& packet); static void GPS_A500_Translate(UC* s, GPS_PAlmanac* alm); @@ -201,8 +201,8 @@ int32 GPS_Init(const char* port) static int32 GPS_A000(const char* port) { gpsdevh* fd; - GPS_PPacket tra; - GPS_PPacket rec; + GPS_Packet tra; + GPS_Packet rec; int16 version; int16 id; @@ -379,16 +379,16 @@ carry_on: ** Extract protocol capabilities ** This routine could do with re-writing. It's too long and obtuse. ** -** @param [r] packet [GPS_PPacket] A001 protocol packet +** @param [r] packet [GPS_Packet] A001 protocol packet ** ** @return [void] ************************************************************************/ -static void GPS_A001(GPS_PPacket& packet) +static void GPS_A001(const GPS_Packet& packet) { US lasta=0; int32 entries = packet.n / 3; - UC* p = packet.data; + const UC* p = packet.data; for (int32 i=0; iDevice_Flush)(fd); } -int32 GPS_Write_Packet(gpsdevh* fd, GPS_PPacket& packet) +int32 GPS_Write_Packet(gpsdevh* fd, const GPS_Packet& packet) { return (ops->Write_Packet)(fd, packet); } -int32 GPS_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) +int32 GPS_Packet_Read(gpsdevh* fd, GPS_Packet* packet) { return (ops->Read_Packet)(fd, packet); } -bool GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Send_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec) { return (ops->Send_Ack)(fd, tra, rec); } -bool GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Get_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec) { return (ops->Get_Ack)(fd, tra, rec); } -void GPS_Make_Packet(GPS_PPacket* packet, US type, UC* data, uint32 n) +void GPS_Make_Packet(GPS_Packet* packet, US type, UC* data, uint32 n) { packet->type = type; if (n > 0) { diff --git a/jeeps/gpsdevice.h b/jeeps/gpsdevice.h index 583f4afb7..f893adf27 100644 --- a/jeeps/gpsdevice.h +++ b/jeeps/gpsdevice.h @@ -37,16 +37,17 @@ int32 GPS_Device_Read(int32 ignored, void* ibuf, int size); int32 GPS_Device_Write(int32 ignored, const void* obuf, int size); void GPS_Device_Error(char* hdr, ...); - int32 GPS_Write_Packet(gpsdevh* fd, GPS_PPacket& packet); - bool GPS_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); - int32 GPS_Packet_Read(gpsdevh* fd, GPS_PPacket* packet); - bool GPS_Get_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); - - typedef int32(*gps_device_op)(gpsdevh*); - typedef int32(*gps_device_op5)(const char*, gpsdevh** fd); - typedef bool(*gps_device_op10)(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); - typedef int32(*gps_device_op12)(gpsdevh* fd, GPS_PPacket& packet); - typedef int32(*gps_device_op13)(gpsdevh* fd, GPS_PPacket* packet); + int32 GPS_Write_Packet(gpsdevh* fd, const GPS_Packet& packet); + bool GPS_Send_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec); + int32 GPS_Packet_Read(gpsdevh* fd, GPS_Packet* packet); + bool GPS_Get_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec); + + using gps_device_op = int32 (*)(gpsdevh*); + using gps_device_op5 = int32 (*)(const char*, gpsdevh** fd); + using gps_device_op10 = bool (*)(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec); + using gps_device_op12 = int32 (*)(gpsdevh* fd, const GPS_Packet& packet); + using gps_device_op13 = int32 (*)(gpsdevh* fd, GPS_Packet* packet); + typedef struct { gps_device_op5 Device_On; gps_device_op Device_Off; diff --git a/jeeps/gpsdevice_usb.cc b/jeeps/gpsdevice_usb.cc index 31583c5c1..15e37c19e 100644 --- a/jeeps/gpsdevice_usb.cc +++ b/jeeps/gpsdevice_usb.cc @@ -42,7 +42,7 @@ static int32 gdu_off(gpsdevh* dh) return gusb_close(dh); } -static int32 gdu_read(gpsdevh* fd, GPS_PPacket* packet) +static int32 gdu_read(gpsdevh* fd, GPS_Packet* packet) { /* Default is to eat bulk request packets. */ return GPS_Packet_Read_usb(fd, packet, 1); diff --git a/jeeps/gpsread.cc b/jeeps/gpsread.cc index 512c647af..db9aef4bd 100644 --- a/jeeps/gpsread.cc +++ b/jeeps/gpsread.cc @@ -64,12 +64,12 @@ time_t GPS_Time_Now() ** Read a packet ** ** @param [r] fd [int32] file descriptor -** @param [w] packet [GPS_PPacket *] packet string +** @param [w] packet [GPS_Packet *] packet string ** ** @return [int32] number of bytes read **********************************************************************/ -int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) +int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_Packet* packet) { time_t start; int32 len = 0; @@ -181,13 +181,13 @@ int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet) ** Check that returned packet is an ack for the packet sent ** ** @param [r] fd [int32] file descriptor -** @param [r] tra [GPS_PPacket *] packet just transmitted -** @param [r] rec [GPS_PPacket *] packet to receive +** @param [r] tra [GPS_Packet *] packet just transmitted +** @param [r] rec [GPS_Packet *] packet to receive ** ** @return [bool] true if ACK **********************************************************************/ -bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec) +bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_Packet *tra, GPS_Packet *rec) { if (!GPS_Serial_Packet_Read(fd, rec)) { return false; diff --git a/jeeps/gpsread.h b/jeeps/gpsread.h index 6c57f2a2e..d8461ac22 100644 --- a/jeeps/gpsread.h +++ b/jeeps/gpsread.h @@ -5,7 +5,7 @@ #include "jeeps/gps.h" time_t GPS_Time_Now(); - int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_PPacket* packet); - bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec); + int32 GPS_Serial_Packet_Read(gpsdevh* fd, GPS_Packet* packet); + bool GPS_Serial_Get_Ack(gpsdevh *fd, GPS_Packet *tra, GPS_Packet *rec); #endif diff --git a/jeeps/gpsrqst.cc b/jeeps/gpsrqst.cc index 457eff8b1..82a28adbc 100644 --- a/jeeps/gpsrqst.cc +++ b/jeeps/gpsrqst.cc @@ -69,8 +69,8 @@ int32 GPS_Rqst_Send_Time(gpsdevh* fd, time_t Time) ************************************************************************/ static int32 GPS_A600_Rqst(gpsdevh* fd, time_t Time) { - GPS_PPacket tra; - GPS_PPacket rec; + GPS_Packet tra; + GPS_Packet rec; switch (gps_date_time_type) { case pD600: @@ -134,8 +134,8 @@ int32 GPS_Rqst_Send_Position(gpsdevh* fd, double lat, double lon) ************************************************************************/ static int32 GPS_A700_Rqst(gpsdevh* fd, double lat, double lon) { - GPS_PPacket tra; - GPS_PPacket rec; + GPS_Packet tra; + GPS_Packet rec; switch (gps_position_type) { case pD700: diff --git a/jeeps/gpssend.cc b/jeeps/gpssend.cc index 71e7dc46a..07ff72e3d 100644 --- a/jeeps/gpssend.cc +++ b/jeeps/gpssend.cc @@ -34,15 +34,15 @@ ** ** Forms a complete packet to send on serial port * -** @param [r] in [GPS_PPacket *] packet string with portable packet data -** @param [w] out [GPS_Serial_PPacket *] packet string suitable for serial port +** @param [r] in [GPS_Packet *] packet string with portable packet data +** @param [w] out [GPS_Serial_Packet *] packet string suitable for serial port ** ** @return [US] number of data bytes to send ************************************************************************/ static US -Build_Serial_Packet(GPS_PPacket in, GPS_Serial_PPacket out) +Build_Serial_Packet(const GPS_Packet& in, GPS_Serial_Packet* out) { - UC* p; + const UC* p; UC* q; UC chk = 0; US bytes = 0; @@ -111,16 +111,16 @@ DiagS(void* buf, size_t sz) ** Forms a complete packet to send ** ** @param [w] fd [int32] file descriptor -** @param [r] packet [GPS_PPacket] packet +** @param [r] packet [GPS_Packet] packet ** ** @return [int32] number of bytes in the packet ************************************************************************/ -int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet) +int32 GPS_Serial_Write_Packet(gpsdevh* fd, const GPS_Packet& packet) { int32 ret; const char* m1, *m2; - GPS_Serial_OPacket ser_pkt; + GPS_Serial_Packet ser_pkt; UC ser_pkt_data[MAX_GPS_PACKET_SIZE * sizeof(UC)]; US bytes; @@ -183,13 +183,13 @@ int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet) ** Send an acknowledge packet ** ** @param [w] fd [int32] file descriptor -** @param [r] tra [GPS_PPacket *] packet to transmit -** @param [r] rec [GPS_PPacket *] last packet received +** @param [r] tra [GPS_Packet *] packet to transmit +** @param [r] rec [GPS_Packet *] last packet received ** ** @return [bool] success ************************************************************************/ -bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec) +bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec) { UC data[2]; diff --git a/jeeps/gpssend.h b/jeeps/gpssend.h index 6a213dc88..c478e9880 100644 --- a/jeeps/gpssend.h +++ b/jeeps/gpssend.h @@ -6,10 +6,10 @@ #define GPS_ARB_LEN 1024 - int32 GPS_Serial_Write_Packet(gpsdevh* fd, GPS_PPacket& packet); - bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_PPacket* tra, GPS_PPacket* rec); + int32 GPS_Serial_Write_Packet(gpsdevh* fd, const GPS_Packet& packet); + bool GPS_Serial_Send_Ack(gpsdevh* fd, GPS_Packet* tra, GPS_Packet* rec); - void GPS_Make_Packet(GPS_PPacket* packet, US type, UC* data, uint32 n); + void GPS_Make_Packet(GPS_Packet* packet, US type, UC* data, uint32 n); #endif diff --git a/jeeps/gpsserial.cc b/jeeps/gpsserial.cc index d0f8107ab..2a3cb4b2e 100644 --- a/jeeps/gpsserial.cc +++ b/jeeps/gpsserial.cc @@ -234,8 +234,8 @@ int32 GPS_Serial_Read(gpsdevh* dh, void* ibuf, int size) int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br) { static UC data[4]; - GPS_PPacket tra; - GPS_PPacket rec; + GPS_Packet tra; + GPS_Packet rec; win_serial_data* wsd = (win_serial_data*)fd; DWORD speed = mkspeed(br); @@ -614,8 +614,8 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br) struct termios tty; static UC data[4]; - GPS_PPacket tra; - GPS_PPacket rec; + GPS_Packet tra; + GPS_Packet rec; speed_t speed = mkspeed(br); diff --git a/jeeps/gpsusbcommon.h b/jeeps/gpsusbcommon.h index 8b29d4040..d17456799 100644 --- a/jeeps/gpsusbcommon.h +++ b/jeeps/gpsusbcommon.h @@ -23,9 +23,9 @@ * The 'low level ops' are registered by the OS layer (win32, libusb, etc.) * to provide gruntwork features for the common USB layer. */ -typedef int (*gusb_llop_get)(garmin_usb_packet* ibuf, size_t sz); -typedef int (*gusb_llop_send)(const garmin_usb_packet* opkt, size_t sz); -typedef int (*gusb_llop_close)(gpsdevh* dh, bool exit_lib); +using gusb_llop_get = int (*)(garmin_usb_packet* ibuf, size_t sz); +using gusb_llop_send = int (*)(const garmin_usb_packet* opkt, size_t sz); +using gusb_llop_close = int (*)(gpsdevh* dh, bool exit_lib); typedef struct gusb_llops { gusb_llop_get llop_get_intr; diff --git a/jeeps/gpsusbint.h b/jeeps/gpsusbint.h index 50e152263..cba2bee1c 100644 --- a/jeeps/gpsusbint.h +++ b/jeeps/gpsusbint.h @@ -21,7 +21,7 @@ */ -int32 GPS_Packet_Read_usb(gpsdevh* fd, GPS_PPacket* packet, int eatbulk); -void GPS_Make_Packet_usb(GPS_PPacket* packet, UC type, UC* data, int16 n); -int32 GPS_Write_Packet_usb(gpsdevh* fd, GPS_PPacket& packet); +int32 GPS_Packet_Read_usb(gpsdevh* fd, GPS_Packet* packet, int eatbulk); +void GPS_Make_Packet_usb(GPS_Packet* packet, UC type, UC* data, int16 n); +int32 GPS_Write_Packet_usb(gpsdevh* fd, const GPS_Packet& packet); diff --git a/jeeps/gpsusbread.cc b/jeeps/gpsusbread.cc index e6e10062d..59d83c352 100644 --- a/jeeps/gpsusbread.cc +++ b/jeeps/gpsusbread.cc @@ -28,7 +28,7 @@ * Negative on error. * 1 if read success - even if empty packet. */ -int32 GPS_Packet_Read_usb(gpsdevh* /*unused*/, GPS_PPacket* packet, int eat_bulk) +int32 GPS_Packet_Read_usb(gpsdevh* /*unused*/, GPS_Packet* packet, int eat_bulk) { int32 n; int32 payload_size; diff --git a/jeeps/gpsusbsend.cc b/jeeps/gpsusbsend.cc index 030776587..90da93d05 100644 --- a/jeeps/gpsusbsend.cc +++ b/jeeps/gpsusbsend.cc @@ -26,7 +26,7 @@ #include int32 -GPS_Write_Packet_usb(gpsdevh* /*unused*/, GPS_PPacket& packet) +GPS_Write_Packet_usb(gpsdevh* /*unused*/, const GPS_Packet& packet) { garmin_usb_packet gp; memset(&gp, 0, sizeof(gp)); -- 2.30.2